home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
gnu
/
dirent.lha
/
dirent
/
testdir.c
< prev
Wrap
C/C++ Source or Header
|
1988-09-02
|
895b
|
56 lines
/*
testdir -- basic test for C library directory access routines
last edit: 25-Apr-1987 D A Gwyn
*/
#include <sys/types.h>
#include <stdio.h>
#include <dirent.h>
extern void exit();
extern int strcmp();
main( argc, argv )
int argc;
register char **argv;
{
extern int errno;
register DIR *dirp;
register struct dirent *dp;
int nerrs = 0; /* total not found */
if ( (dirp = opendir( "." )) == NULL )
{
(void)fprintf( stderr, "Cannot open \".\" directory\n" );
exit( 1 );
}
while ( --argc > 0 )
{
++argv;
while ( (dp = readdir( dirp )) != NULL )
{
if ( strcmp( dp->d_name, *argv ) == 0 )
{
(void)printf( "\"%s\" found.\n", *argv );
break;
}
}
if ( dp == NULL )
{
if (errno)
perror("");
(void)printf( "\"%s\" not found.\n", *argv );
++nerrs;
}
rewinddir( dirp );
}
(void)closedir( dirp );
exit( nerrs );
}